package com.mtzqc.common.service.impl

import com.blankj.utilcode.util.GsonUtils
import com.didi.drouter.annotation.Service
import com.didi.drouter.api.Extend
import com.mtzqc.common.service.JsonService
import rxhttp.wrapper.entity.ParameterizedTypeImpl

@Service(function = [JsonService::class], cache = Extend.Cache.SINGLETON)
class JsonImpl : JsonService {

    override fun toJson(value: Any): String {
        return GsonUtils.toJson(value)
    }

    override fun <T> pare(json: String, clazz: Class<T>): T {
        return GsonUtils.fromJson(json, clazz)
    }

    override fun <T> pareList(json: String, clazz: Class<T>): List<T> {
        return GsonUtils.fromJson(
            json,
            ParameterizedTypeImpl[List::class.java, clazz]
        )
    }
}